package com.turing.common.util;

import com.itextpdf.kernel.pdf.canvas.parser.EventType;
import com.itextpdf.kernel.pdf.canvas.parser.data.IEventData;
import com.itextpdf.kernel.pdf.canvas.parser.data.ImageRenderInfo;
import com.itextpdf.kernel.pdf.canvas.parser.listener.IEventListener;
import com.itextpdf.text.pdf.parser.PdfImageObject;
import com.itextpdf.text.pdf.parser.RenderListener;
import com.itextpdf.text.pdf.parser.TextRenderInfo;

import java.io.IOException;
import java.util.Set;

/**
 * @ClassName ImageRenderListener
 * @Description TODO
 * @Author Distance
 * @Date 2022/4/15 11:55
 * @Version 1.0
 **/
public class ImageRenderListener implements IEventListener {

    private final ThreadLocal<Boolean> thread_local = new ThreadLocal<>();

    ImageRenderListener() {
        thread_local.set(false);
    }

    @Override
    public void eventOccurred(IEventData iEventData, EventType eventType) {
        if(iEventData instanceof ImageRenderInfo) {
            thread_local.set(true);
        }
    }

    @Override
    public Set<EventType> getSupportedEvents() {
        return null;
    }

    public boolean get(){
        return thread_local.get();
    }

    public void reset() {
        thread_local.set(false);
    }

    public void remove() {
        thread_local.remove();
    }
}
